class WorkshopsController < ApplicationController

  before_filter :workshop_authorize

  def index
    @workshops = Workshop.all
  end


  def new
    @workshop = Workshop.new
  end


  def edit
    @workshop = Workshop.find(params[:id])
  end


  def create
    @workshop = Workshop.new(params[:workshop])
    if @workshop.save
      redirect_to(:action => 'edit', :id => @workshop.id)
    else
      render :action => 'new'
    end
  end

  def destroy
    @workshop = Workshop.find(params[:id])
    @workshop.destroy
    redirect_to(:action => 'index')
  end

  def update
    @workshop = Workshop.find(params[:id])
    if @workshop.update_attributes(params[:workshop])
      redirect_to(:action => 'index')
    else
      render :action => 'edit'
    end
  end

  private

  def workshop_authorize
    head :forbidden if !current_user.is_administrator
  end

end
